# Maintainer: Dominic Sisneros <dsisnero@gmail.com>

_realname=mtex2MML
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.1
pkgrel=2
pkgdesc="A Bison grammar to convert TeX math into MathML (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/gjtorikian/mtex2MML/"
license=('LGPL')
license=('GPL' 'MPL' 'LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-python3"
             'bison'
             'flex'
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
            )
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/gjtorikian/${_realname}/archive/v${pkgver}.tar.gz"
        001-install-rules.patch)
sha256sums=('977be19419572da01c4c86789c28a6a0d8cd74cdab6e30f77d6ab7dbd38e7195'
            '32a4fbcf633d165c4fd36b2f4af8b902d0509dcca0fd3585e244e9cad65e7eee')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/001-install-rules.patch"
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DBUILD_STATIC_LIBS=YES \
    -DBUILD_SHARED_LIBS=YES \
    -DBUILD_TESTING=YES \
    ../${_realname}-${pkgver}

  make ${MAKEFLAGS}
}

# check() {
#     #make check
# }

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" -j1 install
}
